##PBAR_ConsolidateRadiography.py
import numpy as np
import csv

datasetNameList = ('Coll-BS-03282013-after-Pb-Al-runs-', 'Coll-BS-03282013-after-Pb-Fe-runs-', \
                   'Coll-BS-03282013-before-Pb-Al-runs-', 'Coll-BS-03282013-before-Pb-Fe-runs-', \
                   'Coll-BS-03292013-after-4Pb-Al-runs-', 'Coll-BS-03292013-before-4Pb-Al-runs-', \
                   'Dark-Coll-BS-03282013-after-Pb-Al-runs-', 'Dark-Coll-BS-03282013-after-Pb-Fe-runs-', \
                   'Dark-Coll-BS-03282013-before-Pb-Al-runs-', 'Dark-Coll-BS-03282013-before-Pb-Fe-runs-', \
                   'dark-current-03292013-after-4Pb-Al-', 'dark-current-03292013-before-4Pb-Al-')

dirPath = r'C:\Users\jkwong\Documents\Work\PBAR\data\Array-Response\\'


for ii in range(0, len(datasetNameList)):
    dat = np.zeros((548,5))
    for jj in range(0,5):
        f = jj+1
        fullfileName = dirPath + datasetNameList[ii] + str(f) + '.csv'
        temp = np.genfromtxt(fullfileName, delimiter = '\t')
        dat[:,jj] = temp
    temp = dat.mean(axis = 1)
    fullfileName = dirPath + datasetNameList[ii] + 'all' + '.csv'
    fid = open(fullfileName, "wb")
    open_file_object = csv.writer(fid, delimiter = ',')
    for kk in range(0, len(temp)):
        open_file_object.writerow(  np.hstack((dat[kk,:], temp[kk]))   )
    fid.close()
